import request from "@/plugin/axios";
// import util from "@/libs/util";

export const startApiReq = (transCode, body) => {
  // const token = util.cookies.get("token");
  const head = {
    // token,
    timestamp: new Date().getTime(),
    transCode,
  };
  const data = { head, body };
  return request({
    url: "api/api",
    method: "post",
    data,
  });
};

export const startCerpApiReq = (transCode, body) => {
  // const token = util.cookies.get("token");
  const head = {
    // token,
    timestamp: new Date().getTime(),
    transCode,
  };
  const data = { head, body };
  return request({
    url: "cerp_api/api",
    method: "post",
    data,
  });
};

export const startReportApiReq = (transCode, body) => {
  // const token = util.cookies.get("token");
  const head = {
    // token,
    timestamp: new Date().getTime(),
    transCode,
  };
  const data = { head, body };
  return request({
    url: "cerp_api/report_api",
    method: "post",
    data,
  });
};

export const startFinanceApiReq = (transCode, body) => {
  // const token = util.cookies.get("token");
  const head = {
    // token,
    timestamp: new Date().getTime(),
    transCode,
  };
  const data = { head, body };
  return request({
    url: "cerp_api/finance_api",
    method: "post",
    data,
  });
};

/**
 * 获取理算系数
 * @param product_name 品名
 * @param material 材质
 * @param specifications 规格
 * @param origin_place 产地
 * @returns {Promise<*>}
 */
export const getReckonCoefficient = async ({ product_name, material, specifications, origin_place }) => {
  if (product_name && material && specifications && origin_place) {
    const res = await startCerpApiReq("E3000001", {
      product_name,
      material,
      specifications,
      origin_place,
    });
    if (res.data && res.data != "0.000000" && res.data != "0") {
      return Promise.resolve(res.data * 1);
    } else {
      return Promise.resolve("");
    }
  } else {
    return Promise.resolve("");
  }
};
